# dockerfile.alpine-ssh.sh

FROM alpine:3.16 AS temp

RUN date  && \
    sed -i 's/dl.*org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk add --no-cache tzdata

FROM alpine:3.16
#MAINTAINER Elven (elven89@qq.com)

COPY --from=temp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
COPY --from=temp /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai

RUN date  && \
    sed -i 's/dl.*org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk add --no-cache openssh-server  && \
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config && \
    sed -ir '5 iPort 22\nPermitEmptyPasswords no\nUseDNS no\n' /etc/ssh/sshd_config && \
    ssh-keygen -t rsa -P "" -f /etc/ssh/ssh_host_rsa_key && \
    ssh-keygen -t ecdsa -P "" -f /etc/ssh/ssh_host_ecdsa_key && \
    ssh-keygen -t ed25519 -P "" -f /etc/ssh/ssh_host_ed25519_key && \
    mkdir -p /root/.ssh  && \
    touch /root/.ssh/authorized_keys && \
    chmod 600 /root/.ssh/authorized_keys && \
    echo "root:admin" | chpasswd

# 开放22端口
EXPOSE 22

# 执行ssh启动命令
CMD ["/usr/sbin/sshd", "-D"]

# docker build --no-cache -t alpine:ssh -f dockerfile.alpine-ssh.sh .
# docker images alpine

# registry.aliyuncs.com/elvin/alpine:ssh
